home *** CD-ROM | disk | FTP | other *** search
/ Mac Magazin/MacEasy 11 / Mac Magazin and MacEasy Magazine CD - Issue 11.iso / Sharewarebibliothek / Entwickler / WASTE 1.1b1 Distribution / Demo Source / DialogUtils.p next >
Text File  |  1995-06-01  |  3KB  |  122 lines

  1. unit DialogUtils;
  2.  
  3. { WASTE DEMO PROJECT: }
  4. { Dialog Utilities }
  5.  
  6. { Copyright © 1993-1995 Marco Piovanelli }
  7. { All Rights Reserved }
  8.  
  9. interface
  10.     uses
  11.         Dialogs;
  12.  
  13.     function GetMyStandardDialogFilter: ModalFilterUPP;
  14.  
  15.     function GetDialogItemType (dialog: DialogRef;
  16.                                     item: Integer): Integer;
  17.     function GetDialogItemHandle (dialog: DialogRef;
  18.                                     item: Integer): Handle;
  19.     function GetDialogItemRect (dialog: DialogRef;
  20.                                     item: Integer): Rect;
  21.     procedure SetDialogItemProc (dialog: DialogRef;
  22.                                     item: Integer;
  23.                                     proc: UserItemUPP);
  24.  
  25. implementation
  26.  
  27.     procedure DoWindowEvent (var event: EventRecord);
  28.     external;        { defined in DemoEvents.p }
  29.  
  30.     function MyStandardDialogFilter (dialog: DialogRef;
  31.                                     var event: EventRecord;
  32.                                     var item: Integer): Boolean;
  33.         var
  34.             savePort: GrafPtr;
  35.             standardFilter: ProcPtr;
  36.     begin
  37.         MyStandardDialogFilter := false;
  38.  
  39. { set up thePort }
  40.         GetPort(savePort);
  41.         SetPort(dialog);
  42.  
  43. { intercept window events directed to windows behind the dialog }
  44.         if (event.what in [updateEvt, activateEvt]) then
  45.             if (DialogRef(event.message) <> dialog) then
  46.                 DoWindowEvent(event);
  47.  
  48. { is the default item a pushbutton? }
  49.         if (GetDialogItemType(dialog, DialogPeek(dialog)^.aDefItem) = kControlDialogItem + kButtonDialogItem) then
  50.  
  51. { yes, so tell the Dialog Manager to care about its outline }
  52.             if (SetDialogDefaultItem(dialog, DialogPeek(dialog)^.aDefItem) <> noErr) then
  53.                 ;
  54.  
  55. { call the standard Dialog Manager filter procedure }
  56.         if (GetStdFilterProc(standardFilter) = noErr) then
  57.             MyStandardDialogFilter := CallModalFilterProc(dialog, event, item, standardFilter);
  58.  
  59. { restore thePort }
  60.         SetPort(savePort);
  61.  
  62.     end;  { MyStandardDialogFilter }
  63.  
  64.     var
  65.  
  66. { static variable for GetMyStandardDialogFilter }
  67.         sMyStandardDialogFilterProc: ModalFilterUPP;
  68.  
  69.     function GetMyStandardDialogFilter: ModalFilterUPP;
  70.     begin
  71.         if (sMyStandardDialogFilterProc = nil) then
  72.             sMyStandardDialogFilterProc := NewModalFilterProc(@MyStandardDialogFilter);
  73.         GetMyStandardDialogFilter := sMyStandardDialogFilterProc;
  74.     end;  { GetMyStandardDialogFilter }
  75.  
  76.     function GetDialogItemType (dialog: DialogRef;
  77.                                     item: Integer): Integer;
  78.         var
  79.             itemType: Integer;
  80.             itemHandle: Handle;
  81.             itemRect: Rect;
  82.     begin
  83.         GetDialogItem(dialog, item, itemType, itemHandle, itemRect);
  84.         GetDialogItemType := itemType;
  85.     end;  { GetDialogItemType }
  86.  
  87.     function GetDialogItemHandle (dialog: DialogRef;
  88.                                     item: Integer): Handle;
  89.         var
  90.             itemType: Integer;
  91.             itemHandle: Handle;
  92.             itemRect: Rect;
  93.     begin
  94.         GetDialogItem(dialog, item, itemType, itemHandle, itemRect);
  95.         GetDialogItemHandle := itemHandle;
  96.     end;  { GetDialogItemHandle }
  97.  
  98.     function GetDialogItemRect (dialog: DialogRef;
  99.                                     item: Integer): Rect;
  100.         var
  101.             itemType: Integer;
  102.             itemHandle: Handle;
  103.             itemRect: Rect;
  104.     begin
  105.         GetDialogItem(dialog, item, itemType, itemHandle, itemRect);
  106.         GetDialogItemRect := itemRect;
  107.     end;  { GetDialogItemRect }
  108.  
  109.     procedure SetDialogItemProc (dialog: DialogRef;
  110.                                     item: Integer;
  111.                                     proc: UserItemUPP);
  112.         var
  113.             itemType: Integer;
  114.             itemHandle: Handle;
  115.             itemRect: Rect;
  116.     begin
  117.         GetDialogItem(dialog, item, itemType, itemHandle, itemRect);
  118.         if (BAND(itemType, $7F) = userItem) then
  119.             SetDialogItem(dialog, item, itemType, Handle(proc), itemRect);
  120.     end;  { SetDialogItemProc }
  121.  
  122. end.